package com.decent.ejfadmin.equity.cardproduct.controller;

import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.equity.cardproduct.service.CardProductService;
import com.decent.ejfadmin.equity.common.CardOperator;
import com.decent.ejfadmin.equity.common.CardType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 权益产品
 *
 * @author weicx
 * @date 2019/03/16
 */
@RestController
@RequestMapping("CardProductController")
@Slf4j
public class CardProductController {
    @Autowired
    private CardProductService cardProductService;

    /**
     * 查询全部卡种
     *
     * @return
     */
    @RequestMapping("queryAllCardOperatorList")
    public List<CardOperator> queryAllCardOperatorList() {
        try {
            return cardProductService.queryAllCardOperatorList();
        } catch (Exception e) {
            log.warn("查询全部卡种异常", e);
            return Collections.emptyList();
        }
    }

    /**
     * 查询权益卡种
     *
     * @param page
     * @param cardOperator
     * @return
     */
    @RequestMapping("queryCardOperatorPage")
    public Page<CardOperator> queryCardOperatorPage(Page page, CardOperator cardOperator) {
        try {
            return cardProductService.queryCardOperatorPage(page, cardOperator);
        } catch (Exception e) {
            log.warn("查询权益卡种异常: [{}]", e);
            page.setResultList(new ArrayList<>());
            page.setTotal(0);
            return page;
        }
    }

    /**
     * 查询全部卡类型
     *
     * @return
     */
    @RequestMapping("queryAllCardTypeList")
    public List<CardType> queryAllCardTypeList() {
        try {
            return cardProductService.queryAllCardTypeList();
        } catch (Exception e) {
            log.warn("查询全部卡类型异常", e);
            return Collections.emptyList();
        }
    }

}
